﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using App_Code;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        var id = GridView1.SelectedDataKey["ID"].ToString();
        if (!string.IsNullOrEmpty(id))
        {
            Response.Redirect("~/Audit.aspx?TableName=Contact&ItemId="+id,false);

            //if you want to show in a popup comment line above and uncomment 2 lines below
            //var url = ResolveUrl("~/AuditPopup.aspx?TableName=Contact&ItemId=" + id);
            //OpenNewWindow(url);
        }

    }
    protected void cmdAdd_Click(object sender, EventArgs e)
    {


        SqlDataSource1.Insert();
        GridView1.DataBind();
    }
    void BindGrid(DataTable dt)
    {

       // GridView1.DataSource = dt;

        //GridView1.DataBind();

    }
    protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e)
    {
        if (HttpContext.Current.User != null)
            e.Command.Parameters["@ChangedBy"].Value = HttpContext.Current.User.Identity.Name;
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
       

    }
    protected void SqlDataSource1_Updating(object sender, SqlDataSourceCommandEventArgs e)
    {
        if (HttpContext.Current.User != null)
            e.Command.Parameters["@ChangedBy"].Value = HttpContext.Current.User.Identity.Name;
    }
    protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
    {
        if(GridView1.Rows!=null  && GridView1.Rows.Count>0)
        {
            GridView1.EditIndex = 0;
        }
    }

    public void OpenNewWindow(string url)
    {

        ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("<script>var mywindow=window.open('{0}','mywindow','menubar=0,resizable=1,width=800,height=350');mywindow.moveTo(100, 100);</script>", url));


    }
}